package edu.upenn.seas.peerreview.smui
import edu.upenn.seas.peerreview.{Id, Sink}
import edu.upenn.seas.peerreview.smui.RGRTestMessages._


/* ********************************************************** */
// Battleship State Machine

class RGRTestClientSM(n: Int)(myId:Id, transport: Sink.T, uiId:Id) extends BSHandler(myId, transport) {
  
  //as soon as you connect, see if your server wants to be friends with you.
  var waitingForResource = false


  send(Id.coordinatorId, RequestResource(n))
  waitingForResource = true
  def handle(e:Envelope) {
    e.contents match {
      case GrantResource(n) if waitingForResource =>
        send(uiId, GrantResource(n))
        println("SM Recieved "+n)
        waitingForResource = false
        send(Id.coordinatorId, ReleaseResource(n))
      case x =>
        println("Badness! "+x)
    }
    
  }
}
